package com.zhejiangzhengyuan.municipal_common.mapper;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhejiangzhengyuan.municipal_common.entity.BridgeGis;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhejiangzhengyuan.municipal_common.entity.vo.BridgeVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * <p>
 * GIS数据库中桥梁表（一路一档建设） Mapper 接口
 * </p>
 *
 * @author linju
 * @since 2019-11-22
 */
@Repository
public interface BridgeGisMapper extends BaseMapper<BridgeGis> {

    //修改坐标
    @Update("update bridge_gis set start_point=ST_GeomFromText('POINT(${lng} ${lat})'),end_point=ST_GeomFromText('POINT(${lng1} ${lat1})') where id=#{id}")
    int updatePoint(@Param("id") Long id, @Param("lng") String lng , @Param("lat") String lat,@Param("lng1") String lng1 , @Param("lat1") String lat1);

    @Update("update bridge_gis set start_point=ST_GeomFromText('POINT(${lng} ${lat})')where id=#{id}\")")
    void updateStartPoint(Long id, String lng, String lat);

    @Update("update bridge_gis set end_point=ST_GeomFromText('POINT(${lng} ${lat})') where id=#{id}\")")
    void updateEndPoint(Long id, String lng, String lat);

    Map<String,Double> findByIdPoint(Long id);

    @Select("select * from bridge_gis where start_point=ST_GeomFromText('POINT(${lng} ${lat})') and end_point=ST_GeomFromText('POINT(${lng1} ${lat1})')")
    BridgeGis findPointByBridge(@Param("lng") String lng , @Param("lat") String lat,@Param("lng1") String lng1 , @Param("lat1") String lat1);

    @Select("select *,concat(concat(st_x(start_point) ,',' ),st_y(start_point)) start_point_string, concat(concat(st_x(end_point) ,',' ),st_y(end_point)) end_point_string  from bridge_gis order by id ")
    Page<BridgeVo> getVoPage(Page<BridgeVo> page);


    Page<BridgeVo> FuzzyBridge(Page<BridgeVo> bridgeGisPage,@Param("bridgeName") String bridgeName,@Param("bridgeCode") String code);
}
